/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exercicio.lista2;

/**
 *
 * @author afonso
 */
public class Questao3 {

    public static void main(String[] args) {
        char[] urna = {'v', 'v', 'v', 'v', 'p', 'p', 'p', 'p', 'p', 'p', 'p'};
        int numExp = 10000;
        int cont = 0;

        for (int i = 0; i < numExp; i++) {
            int pos1 = 0 + (int)(Math.random() * (((urna.length - 1) - 0) + 1));
            int pos2 = 0 + (int)(Math.random() * (((urna.length - 1) - 0) + 1));
            int pos3 = 0 + (int)(Math.random() * (((urna.length - 1) - 0) + 1));

            char bola1 = urna[pos1];
            char bola2 = urna[pos2];
            char bola3 = urna[pos3];

            if(contarBolas(new char[]{bola1, bola2, bola3})){
                cont++;
            }
        }

        double p = (double) cont/numExp;

        System.out.println("Probabilidade = " + p);

    }

    // Vê se tem 2 bolas vermelhas e 1 preta.
    public static boolean contarBolas(char[] bolas){
        int qtdeVermelhas = 0;
        int qtdePretas = 0;
        for (int i = 0; i < bolas.length; i++) {
            if(bolas[i] == 'v'){
                qtdeVermelhas++;
            } else{
                qtdePretas++;
            }
        }
        if(qtdeVermelhas == 2 && qtdePretas == 1){
            return true;
        } else{
            return false;
        }
    }
}
